#include <bits/stdc++.h>
using namespace std;

const int N = 1005;
string a[N];
int b[N];
int top=0;

bool check(string ip)
{
	int len = ip.size(), j;
	int dian=0,mao=0;
	for (j=0; j<len; j++) 
	{
		if (ip[j] == '.') dian++;
		if (ip[j] == ':') mao++;
	}
	if (dian!=3 || mao!=1) return false;
	int s = 0;
	if (ip[0] == '0' && ip[1]!='.') return false;
	if (ip[0]<'0' || ip[j]>'9') return false;
	for (j=0; j<len && ip[j]!='.'; j++) 
	{
		s = s*10+ip[j]-'0';
		if (s<0 ||s>255) return false;
	}
	j++;
	s=0;
	if (ip[j] == '0' && ip[j+1]!='.') return false;
	if (j>=len || ip[j]<'0' || ip[j]>'9') return false;
	for (; j<len && ip[j]!='.'; j++) 
	{
		s = s*10+ip[j]-'0';
		if (s<0 ||s>255) return false;
	}
	j++;
	s=0;
	if (ip[j] == '0' && ip[j+1]!='.') return false;
	if (j>=len || ip[j]<'0' || ip[j]>'9') return false;
	for (; j<len && ip[j]!='.'; j++) 
	{
		s = s*10+ip[j]-'0';
		if (s<0 ||s>255) return false;
	}
	j++;
	s=0;
	if (ip[j] == '0' && ip[j+1]!=':') return false;
	if (j>=len || ip[j]<'0' || ip[j]>'9') return false;
	for (; j<len && ip[j]!=':'; j++) 
	{
		s = s*10+ip[j]-'0';
		if (s<0 ||s>255) return false;
	}
	j++;
	s=0;
	if (ip[j] == '0' && j+1<len) return false;
	if (j>=len || ip[j]<'0' || ip[j]>'9') return false;
	for (;j<len; j++) 
	{
		s = s*10+ip[j]-'0';
		if (s<0 || s>65535) return false;
	}
	return true;
}

int main()
{
	int n;
	freopen("network.in","r",stdin);
	freopen("network.out","w",stdout);
	scanf("%d",&n);
	for (int i=1; i<=n; i++)
	{
		string com, ip;
		cin >> com ;
		cin >> ip;
		if (!check(ip))
		{
			printf("ERR\n");
			continue;
		}
		if (com == "Server")
		{
			bool adj = false;
			for (int j=1; j<=top; j++) if (a[j] == ip)
			{
				printf("FAIL\n");
				adj = true;
				break;
			}
			if (adj) continue;
			top++;
			a[top] = ip;
			b[top] = i;
			printf("OK\n");
		}
		else
		{
			bool adj = true;
			for (int j=1; j<=top; j++) if (a[j] == ip)
			{
				printf("%d\n",b[j]);
				adj = false;
				break;
			}
			if (adj) printf("FAIL\n");
		}
	}
	fclose(stdin);
	fclose(stdout);
	return 0;
}
